import request from '@/utils/request'
import type { Dept, DeptQuery, CreateDept, UpdateDept } from '@/types/api/system/dept'
import type { API } from '@/types/api/response'

/**
 * 获取部门列表
 * @param params 查询参数
 */
export const getDeptList = (params?: DeptQuery) => {
  return request.get<API.Response<Dept[]>>('/api/system/dept/list', { params })
}

/**
 * 获取部门树形结构
 */
export const getDeptTree = () => {
  return request.get<API.Response<Dept[]>>('/api/system/dept/tree')
}

/**
 * 获取部门详情
 * @param id 部门ID
 */
export const getDeptDetail = (id: string) => {
  return request.get<API.Response<Dept>>(`/api/system/dept/${id}`)
}

/**
 * 创建部门
 * @param data 部门数据
 */
export const createDept = (data: CreateDept) => {
  return request.post<API.Response<Dept>>('/api/system/dept', data)
}

/**
 * 更新部门
 * @param id 部门ID
 * @param data 部门数据
 */
export const updateDept = (id: string, data: UpdateDept) => {
  return request.put<API.Response<null>>(`/api/system/dept/${id}`, data)
}

/**
 * 删除部门
 * @param ids 部门ID列表
 */
export const deleteDepts = (ids: string[]) => {
  return request.delete<API.Response<null>>('/api/system/dept', { data: { ids } })
}

/**
 * 修改部门状态
 * @param id 部门ID
 * @param status 状态
 */
export const changeDeptStatus = (id: string, status: 0 | 1) => {
  return request.put<API.Response<null>>(`/api/system/dept/${id}/status`, { status })
} 